<?php


/**
* Puree CMS
* http://www.molotsoft.ru
*
* @package Puree_CMS
* @subpackage Controllers
* @author Ivan Chistyakov <ivan@molotsoft.ru>
* @version $Id: orders_controller.php 865 2010-03-15 10:31:19Z molotsoft@gmail.com $
* @link $HeadURL: http://puree-cms.googlecode.com/svn/trunk/controllers/orders_controller.php $
*/


class OrdersController extends GeneralController {

/******************************************************************************/

var $name = 'Orders';

var $components = array('Auth', 'Cart');

/******************************************************************************/

function beforeFilter() {
	parent::beforeFilter();
	// auth
	if (!(bool)Configure::read('admin')) {
		$this->Auth->userModel = 'Account';
		$this->Auth->userScope = array('Account.activated' => TRUE);
		$this->Auth->fields = array('username' => 'email', 'password' => 'password');
		$this->Auth->authError = __('account_auth_error_message', TRUE);
		$this->Auth->loginError = __('account_login_error_message', TRUE);
		$this->Auth->loginRedirect = array('controller' => 'accounts', 'action' => 'welcome');
		$this->Auth->deny('history');
	}
}

/******************************************************************************/

function history() {
	$conditions = array('Order.account_id' => $this->Auth->user('id'));
	$this->set('paginated', $paginated = (bool)$this->Order->paginateLimit);
	if ($paginated) {
		$this->paginate = array('conditions' => $conditions);
		$this->set('paginate_limit', $this->paginate['limit'] = $this->Order->paginateLimit);
		$this->set('rows', $rows = $this->paginate('Order', $conditions));
	} else {
		$this->set('rows', $rows = $this->Order->find('all', array('conditions' => $conditions)));
	}
}

/******************************************************************************/

}


?>